#!/usr/bin/env python
# encoding: utf-8
'''
@author: liuchong
@contact: lucas@007vin.com
@software: garner
@file: banzhou.py
@time: 2020/8/24 2:44 下午
@desc:
'''

import os
import pandas as pd
from models.audi.audi_all import CarsAudiAll
for root,p,files in os.walk('/Users/liuchong/Downloads/audi_all'):
    for fi in files:
        fi = '/'.join([root,fi])
        df = pd.read_csv(fi)
        df.fillna('', inplace=True)
        for index, row in df.iterrows():
            print(row.to_dict())
            audi = CarsAudiAll()

            audi.pid = row.to_dict()['pid']

            if not row.to_dict()['standard_label']:
                audi.standard_label = ''
            else:
                audi.standard_label = row.to_dict()['standard_label']

            if not row.to_dict()['label']:
                audi.label = ''
            else:
                audi.label = row.to_dict()['label']

            if not row.to_dict()['desc']:
                audi.desc = ''
            else:
                audi.desc = row.to_dict()['desc']

            if not row.to_dict()['engine_code']:
                audi.engine_code = ''
            else:
                audi.engine_code = row.to_dict()['engine_code']

            if not row.to_dict()['cylinder']:
                audi.cylinder = ''
            else:
                audi.cylinder = row.to_dict()['cylinder']

            if not row.to_dict()['transmission']:
                audi.transmission = ''
            else:
                audi.transmission = row.to_dict()['transmission']

            if not row.to_dict()['replace']:
                audi.replace = ''
            else:
                audi.replace = row.to_dict()['replace']

            if not row.to_dict()['drive']:
                audi.drive = ''
            else:
                audi.drive = row.to_dict()['drive']

            if not row.to_dict()['差速器']:
                audi.diff_mech = ''
            else:
                audi.diff_mech = row.to_dict()['差速器']

            if not row.to_dict()['displacement']:
                audi.displacement = ''
            else:
                audi.displacement = row.to_dict()['displacement']
            audi.save()
